package com.rayc.mall.common.result;

import com.rayc.mall.common.constant.Constants;
import com.rayc.mall.common.enums.ResponseCode;
import lombok.Data;

import java.io.Serializable;

/**
 * @Author: Ray-C
 * @CreateTime: 2025-03-23
 * @Description: 统一返回结果
 * @Version: 1.0
 */
@Data
public class Result<T> implements Serializable {

    // 状态码
    private Integer code;
    // 成功或失败
    private String status;
    // 显示给用户的提醒信息
    private String info;
    // 数据
    private T data;

    public static <T> Result<T> success() {
        Result<T> result = new Result<>();
        result.code = ResponseCode.SUCCESS.getCode();
        result.status = "success";
        result.info = Constants.MESSAGE_SUCCESS;
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = success();
        result.data = object;
        return result;
    }

    public static <T> Result<T> error(Integer code, String msg) {
        Result<T> result = new Result<>();
        result.code = code;
        result.status = "error";
        result.info = msg;
        return result;
    }

}
